<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of adver
 *
 * @author Admin
 */
class Application_Model_Adver extends Zend_Db_Table_Abstract 
{
     public function getAdver($id) {
        $this->_name = 'context_adver';
        $select = $this->select()
                       ->from($this->_name)
                       ->join(array('can' => 'context_adver_connection'), 'can.id_context_adv = context_adver.id')
                       ->join(array('as' => 'advertising_spaces'), 'as.id = can.id_adv_space', array('id_site' => 'as.id_site'))
                       ->where('context_adver.id =?', $id)
                       ->setIntegrityCheck(false);
        return $this->fetchRow($select);
    }
    
    public function getSelectAdvSpace($code) {
        $this->_name = 'advertising_spaces';
        $select = $this->select()
                       ->from($this->_name)
                       ->where('code =?', $code);
        return $this->fetchRow($select);
    }
    
    public function getSpaceContextAdvers($idSpace) {
        $select = $this->select()
                       ->from(array('ca' => 'context_adver'))
                       ->join(array('cac' => 'context_adver_connection'),
                                    'ca.id = cac.id_context_adv')
                       ->where('cac.id_adv_space =?', $idSpace)
                       ->setIntegrityCheck(false);
        return $this->fetchAll($select)->toArray();
    }
    
    public function addAdverSpace($data) {
        $this->_name = 'advertising_spaces';
        $this->insert($data);
        return $this->getAdapter()->lastInsertId();
    }
    /**
     * Сохраняем настройки контекстной рекламмы
     * @param array $data 
     */
    public function saveContextSettings($data) {
        $this->_name = 'site_context_settings';
        $this->insert($data);
    }
    /**
     * Выборка стилей для рекламной компании
     * @param int $id_site - id сайта на котором будет розмещатся реклама
     * @return array 
     */
    public function getContextSiteSettings($id_site) {
        $this->_name = 'site_context_settings';
        $select = $this->select()->from($this->_name)
                ->where('id_site = ?', intval($id_site));
        return $this->fetchRow($select);
    }
}

?>
